# -*- coding: utf-8 -*-
import formencode

from cibynet.model.utils import UnicodeProperty
from cibynet.model.utils import GetAllObjects, GetOneObject

class Bank(object):
  """Bank object. Basically just the name at this point.
  """
  name = UnicodeProperty("_name")
  
  def __init__(self, name):
    """
    Arguments:
      - name: unicode, the name of the bank.
    """
    self.name = name
    
    
class BankIdValidator(formencode.validators.FancyValidator):
  """Validate that the given id corresponds to a bank in DB.
  """
  
  def to_python(self, value, c):
    """Returns room object.
    """
    if len(value) == 0: 
      if self.not_empty:
        raise formencode.validators.Invalid('Please select a bank', value, c)
      return None
    bank = GetOneObject(Bank, id=int(value))
    if bank is None:
      raise formencode.validators.Invalid('This bank is not known...', value, c)
    return bank

